import { getPayAll } from "../../../network/order"

// pages/order/pay-detail/pay-detail.js
Page({
  data: {
    detailInfo:null,
    totalPrice:null,
    picArr:[]
  },
  onLoad: function (options) {
    this._getPayAll(options.order_id)
  },
  // 预览图片
  previewImg: function (e) {
    //获取当前图片的下标
    var index = e.currentTarget.dataset.index;
    //所有图片
    var pics = this.data.picArr;
    wx.previewImage({
      //当前显示图片
      current: pics[index],
      //所有图片
      urls: pics
    })
  },
  //      网络请求      //
  async _getPayAll(order_id){
    const res = await getPayAll(order_id)
    if(res.code === 200){
      this.setData({
        detailInfo: res.data
      })
      let arr = []
      res.data.forEach(res=>{
        arr.push(res.proof_pic)
      })
      this.setData({
        picArr:arr
      })
      const totalPrice = this.data.detailInfo.reduce((total,nextVal)=>{
        if(isNaN(nextVal.period_pay)) return total;
        return total*1 + nextVal.period_pay*1
      },0)
      this.setData({totalPrice})
    }
  }
})